package com.hilin.base.server.feign.api;

import com.hilin.entity.anno.NoToken;
import com.hilin.entity.em.LoginOpType;
import com.hilin.entity.po.AccountInfoPo;
import com.hilin.entity.po.OrgInfoPo;
import com.hilin.entity.po.SysAccessPo;
import com.hilin.entity.po.SysRolePo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping()
@FeignClient(value = "hilin-base-server", path = "/base/api/user")
public interface IUserApi {

    @ApiOperation(value = "创建或修改用户信息", notes = "不传ID视为创建，传入id则视为修改")
    @PostMapping("/admin/create")
    AccountInfoPo create(@RequestHeader("token") String token, @RequestParam AccountInfoPo accountInfo);

    @NoToken
    @ApiOperation(value = "创建或修改用户信息", notes = "不传ID视为创建，传入id则视为修改")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "登录账号", name = "accountId", required = true),
            @ApiImplicitParam(value = "登录密码，需要进行md5加密", name = "password", required = true),
            @ApiImplicitParam(value = "机构ID，如果不填写，则可能会有多个相同登录账号（相同账号不同机构）", name = "orgId"),
            @ApiImplicitParam(value = "操作类型 single:单设备登录(如果有账号未退出，则会提示已有账号登录)  force:强制登录(以前登录账号的token会强制失效)", name = "opType")
    })
    @PostMapping("/gen/login")
    AccountInfoPo login(@RequestParam("accountId") String accountId, @RequestParam("password") String password, @RequestParam("orgId") Long orgId, @RequestParam(required = false, value = "opType") LoginOpType opType);

    @NoToken
    @ApiOperation(value = "查询账号所属机构列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "登录账号", name = "accountId", required = true)
    })
    @GetMapping("/gen/accountOrgList")
    List<OrgInfoPo> getAccountOrgList(@RequestParam("accountId") String accountId);

    @ApiOperation(value = "获取所有账号所有权限")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "认证字符串", name = "token", required = true, paramType = "header"),
    })
    @GetMapping("/gen/allAccess")
    List<SysAccessPo> getAllAccess(@RequestHeader("token") String token);

    @ApiOperation(value = "获取所有账号所有角色")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "认证字符串", name = "token", required = true, paramType = "header"),
    })
    @GetMapping("/gen/allRoles")
    List<SysRolePo> getAllRoles(@RequestHeader("token") String token);

    @ApiOperation(value = "获取角色权限")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "认证字符串", name = "token", required = true, paramType = "header"),
    })
    @GetMapping("/gen/role/access")
    List<SysAccessPo> getRoleAccess(@RequestHeader("token") String token, @RequestParam("roleId") Long roleId);

    @ApiOperation(value = "获取角色权限")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "认证字符串", name = "token", required = true, paramType = "header"),
            @ApiImplicitParam(value = "角色ID", name = "roleId", required = true),
    })
    @GetMapping("/gen/pageList")
    List<AccountInfoPo> pageList(@RequestHeader String token, @RequestParam AccountInfoPo accountInfo);
}
